<%@ page language="java" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
${aier_doctype}
<html <s:property value="aier-html-xmlns" escape="false"/>>
<head>
<meta http-equiv="Content-Type" content="${aier_content_type}" />
<meta name="keywords" content="${aier_keyworks}" />
<meta name="description" content="${aier_description}" />
<title>${aier_title}</title>
<link rel="stylesheet" href="${aier_css_url}${aier_jqui_css}ui.css" />
<link rel="Stylesheet" href="${aier_css_url}jq/jq.css" />
<link rel="Stylesheet" href="${aier_css_url}jq/multiselect.css" />
<link rel="stylesheet" href="${aier_css_url}jc/chosen.css" >
<link rel="stylesheet" href="${aier_css_url}social/module/jq-msg.css" />
<link rel="stylesheet" href="${aier_css_url}social/module/reset.css" />
<link rel="stylesheet" href="${aier_css_url}social/school/smanage.css" />

<script type="text/javascript" src="${aier_js_url}j.js"></script>
<script type="text/javascript" src="${aier_js_url}b.js"></script>
<script type="text/javascript" src="${aier_js_url}${aier_jqui_js}ui.js"></script>
<script type="text/javascript" src="${aier_js_url}97/WdatePicker.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/msg.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/cn.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/jq.js"></script>
<script type="text/javascript" src="${aier_js_url}lib/ja.js"></script>
<script type="text/javascript" src="${aier_js_url}jc/cj.js"></script>
<script type="text/javascript" src="${aier_js_url}lib/block.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/multiselect.js"></script>
<script type="text/javascript">
	var global_suffix = "${aier_suffix}", global_url = "${aier_url}", global_uri = "${aier_uri}", global_urijs = "${aier_urijs}",
	global_sid = "${sid}",global_tid = "${tid}";
</script>
</head>
<!-- 教师管理页面 -->
<body>

	<!-- 顶栏 -->
	<s:action name="userhomecomm_homeHead" namespace="/user"
		executeResult="true"></s:action>

	<!-- 正文 -->
	<div id="hfContent" class="ar-content">
		<div class="content-main">
			<!-- 学校名称栏 -->
			<s:action name="scomm_schoolMTitle" namespace="/school" executeResult="true"></s:action>
			<div class="main-content wrap-bg clearfix">
				<!-- 左侧栏 -->
				<s:action name="scomm_schoolMLeft" namespace="/school" executeResult="true"></s:action>
				<!-- 右侧内容 -->
				<div class="ae-right">
					<div class="right-main">
						<div class="right-main-top">
							<div class="binfo-title">
								<span>短信管理</span>
							</div>
							<div class="right-line"></div>
							
						</div>
						<s:if test="%{school.method==2}">  
                            <div>目前学校可用短信为<span id = "mesCount">${school.mesCount}</span>条</div>
                        </s:if>
						<div class="gray6 st-title" style="margin: 10px 0px;font-size: 12px;">
                                <h6>短信后缀：</h6>
                        </div>
                        <!--<s:if test="%{school.mesSuffix==null || school.mesSuffix==''}">  
                            <input maxlength="20" type="text" class="PY-input" id="mesSuffix" style="margin-left: 50px;" value="爱儿360">
                        </s:if>
                        <s:else>  
                            <input maxlength="20" type="text" class="PY-input" id="mesSuffix" style="margin-left: 50px;" value="${school.mesSuffix}">
                        </s:else>-->
                        <input maxlength="20" type="text" class="PY-input" id="mesSuffix" style="margin-left: 50px;" value="${school.mesSuffix}">
						<div class="mib-btn" style="margin-left: 300px;margin-top: -26px;" onclick="siUpdate();"></div>
						<s:if test="%{school.method==2}">  
						<div class="right-main-c">
							<div class="info-tab01">
							<div class="gray6 st-title" style="margin: 10px 0px;font-size: 12px;">
								<h6>分配短信：</h6>
							</div>
								<table style="margin-left: 50px;">

									<tr>
										<th class="gray6" style="*width: 150px;">姓名与账户：</th>
										<td >
											<s:select id="selTname" list="tnameAccountList"
													data-placeholder="请选择或输入姓名" cssClass="chosen" tabindex="4">
											</s:select>
										</td>
										<th class="gray6">职务：</th>
										<td >
											<select id="selSgrade" class="chosen">
												<option value="-1">所有职务</option>
												<c:forEach var="sg" items="${schoolGradeList }">
													<option value="${sg.gid}">${sg.name}</option>
												</c:forEach>
											</select>
										</td>
										<td style="width: 150px;" align="right">
											<a id="stJurBtn" href="javascript:;"
											class="cm-search-btn"></a>
										</td>
									</tr>
								</table>
							</div>
						</div>
						
						<div class="right-main-down">
							<div class="down-inre">
								<table id="sTeachersInfo"></table>
								<div id="sTeachersPage"></div>
							</div>
						</div>
						</s:if>
					</div>
				</div>

			</div>

		</div>
		<!-- footer copyright -->
		<s:action name="userhomecomm_homeFooter" namespace="/user" executeResult="true"></s:action>
		<!-- /footer copyright -->
	</div>
	
	<!-- 弹出层内容 分配短信-->
    <div id="assign_message" title="分配短信" style="display: none;">
        <div class="d_scnOut">
            <div class="d_scname" style="font-size: 14px;">
                <label>短信条数:</label>
            </div>
            <div class="d_sctext" style="font-size: 14px;">
                <input type="text" id="count" class="txt_scname">
            </div>
        </div>
        <button style="margin-top: 20px;margin-left: 150px;" onclick="assignMes();"
                class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
                role="button" aria-disabled="false">
                <span class="ui-button-text">分配</span>
        </button>
    </div>
    
    <!-- 弹出层内容 分配短信历史-->
    <div id="assign_message_history" title="分配短信历史" style="display: none;">
        <div class="d_scnOut">
            <div class="d_scname" style="font-size: 14px;">
                <label>教师姓名:</label>
            </div>
            <div class="d_sctext" style="font-size: 14px;">
                <span id="tname" class="txt_scname"></span>
            </div>
        </div>
        <div class="right-main-down">
            <div class="down-inre">
                <table id="assignInfo"></table>
                <div id="assignPage"></div>
            </div>
        </div>
    </div>

	
</body>
<script type="text/javascript">
    var tid;
	$(".chosen").chosen();
	// 弹出层
    $(function() {
        $("#assign_message").dialog({
            //背景变暗
            modal: true,
            autoOpen : false,
            show : "blind",
            width : "380",
            height : "150"
        });
    
    });
    $(function() {
        $("#assign_message_history").dialog({
            //背景变暗
            modal: true,
            autoOpen : false,
            show : "blind",
            width : "500",
            height : "450"
        });
    
    });
	
	$(document).ready(function(){
		
	    $("#sTeachersInfo").jqGrid({                
	        url:global_url+global_urijs+'schoolmessage_searchSchoolTeacherList'+global_suffix+"?sid="+global_sid,                
	        datatype:"json",                
	        mtype:'GET', 
	        height:'300',
	        width:'770',
	        colNames:['姓名','账号','职务','所在班级','可用短信条数','操作','tid'],                
	        colModel:[                    
	        {name:'tname',index:'tname',width:100,align:'center'},                    
	        {name:'account',index:'account',width:130,align:'center'},         
	        {name:'gname',index:'gname',width:80,align:'center', sortable:false},
	        {name:'classNams_in',index:'classNams_in',width:200,align:'center', sortable:false},
	        {name:'mesCount',index:'mesCount',width:120,align:'center', sortable:false},
	        {name:'option',index:'option',width:200,align:'center', sortable:false},
	        {name:'tid',index:'tid',hidden:true}    
	        ],

	        //autowidth:true,
	        jsonReader: {
	            root:"schoolTeacherList",
	            page: "page",
	            total: "page_count",
	            records : "count",
	            repeatitems: false
	        },
	        pager: jQuery('#sTeachersPage'),
	        prmNames : {page:"page",sort: "sort"},
	        rowNum: 10,
	        //rowList: [10, 20, 30],
	        sortname: 'tname',
	        hidegrid: false,
	        sortorder: 'desc',
	        viewrecords: true,
	        caption: '教师信息',
	        gridComplete:function(){
	            var ids=jQuery("#sTeachersInfo").jqGrid('getDataIDs');
	            for(var i=0; i<ids.length; i++){
	                var id=ids[i];   
	                del = "<a href='javascript:;' class='jqtrow' onclick='assign(" + id + ")'>分配短信</a>"; 
	                ma = "<a href='javascript:;' class='jqtrow' onclick='history(" + id + ")'>分配历史</a>"; 
	                jQuery("#sTeachersInfo").jqGrid('setRowData', ids[i], { option: del + "  " + ma });
	            }
	        }
	    }).navGrid("#sTeachersPage", { edit: false, add: false, del: false, search: false });
	    
	    $("#assignInfo").jqGrid({                
            url:global_url+global_urijs+'schoolmessage_searchAssignList'+global_suffix+"?tid="+tid,                
            datatype:"json",                
            mtype:'GET', 
            height:'260',
            width:'470',
            colNames:['姓名','短信条数','分配时间'],                
            colModel:[                    
            {name:'tname',index:'tname',width:120,align:'center'},                    
            {name:'count',index:'count',width:120,align:'center'},
            {name:'adate',index:'option',width:200,align:'center'}
            ],

            //autowidth:true,
            jsonReader: {
                root:"assignHistoryList",
                page: "page",
                total: "page_count",
                records : "count",
                repeatitems: false
            },
            pager: jQuery('#assignPage'),
            prmNames : {page:"page",sort: "sort"},
            rowNum: 10,
            //rowList: [10, 20, 30],
            sortname: 'adate',
            hidegrid: false,
            sortorder: 'desc',
            viewrecords: true,
            caption: '分配短信',
            gridComplete:function(){
                var ids=jQuery("#assignInfo").jqGrid('getDataIDs');
                for(var i=0; i<ids.length; i++){
                    var id=ids[i];   
                    var adateStr = jQuery("#assignInfo").jqGrid('getRowData', id).adate;
                    if (!isnull(adateStr)) {
                        adateStr = adateStr.split("T")[0]+" "+adateStr.split("T")[1];;
                    }
                    jQuery("#assignInfo").jqGrid('setRowData', ids[i], {adate:adateStr});
                }
            }
        }).navGrid("#assignPage", { edit: false, add: false, del: false, search: false });
	    
	});
	
	//查询
	$("#stJurBtn").click(function() {
		var cid = $('#classid  option:selected').val();
		var nameAndAccount = $("#selTname").val();
		if(nameAndAccount=="所有教师"){
			var account = "";	
		}else{
			var account = nameAndAccount.split(" ")[1];
		}
		var gid = $('#selSgrade  option:selected').val();
		jQuery("#sTeachersInfo").jqGrid('setGridParam',{url:"${aier_url}${aier_urijs}schoolmessage_searchSchoolTeacherList${aier_suffix}?sid="+global_sid
			+"&account="+account+"&gid="+gid,page:1}).trigger("reloadGrid");
		return false;
	});
	
	
	//保存学校短信后缀
	function siUpdate() {
	    var fun = function(data) {
	        if (data.s == 1) {
	            $().message("修改成功!");
	        } else {
	            $().message("修改失败，请稍候再试！");
	        }
	    };
	    exeAjax(
	            ajaxUrl("${aier_url}${aier_urijs}schoolmessage_updateMessageSuffix${aier_suffix}"),
	            fun, {
	                "sid" : global_sid,
	                "mesSuffix" : $("#mesSuffix").val()
	            });

	}
	// 分配短信
	function assign(id) {
        tid = jQuery("#sTeachersInfo").jqGrid('getRowData', id).tid;
        $("#assign_message").dialog("open");
    }
	
	function assignMes() {
        var count=$("#count");
        var countVal=count.val();
        var pattern = new RegExp(/^[0-9]{0,6}$/);    
        var isnum = pattern.exec(countVal);
        if(isnull(isnum)){
            $().message("请输入分配短信条数!");
            count.focus();
            return;
        }
        if (parseInt($("#mesCount").text()) < parseInt(countVal)) {
        	$().message("短信条数不足!");
        	return;
        }
        var fun = function(data) {
            if(1==data.s){
                count.val("");
                $().message("分配成功!");
                $("#sTeachersInfo").trigger("reloadGrid");
                $("#mesCount").text(data.school.mesCount);
                $("#assign_message").dialog("close");
            }else{
                $().message("分配失败,请稍后再试!");
            }
        };
        exeAjax(ajaxUrl("${aier_url}${aier_urijs}schoolmessage_assignMessage${aier_suffix}"), fun, 
        {"tid" :tid,
         "mesCount":countVal,
         "sid":global_sid
         });
    }
	// 查询分配历史
	function history(id) {
        tid = jQuery("#sTeachersInfo").jqGrid('getRowData', id).tid;
        $("#tname").html(jQuery("#sTeachersInfo").jqGrid('getRowData', id).tname);
        
        jQuery("#assignInfo").jqGrid('setGridParam',{url:"${aier_url}${aier_urijs}schoolmessage_searchAssignList${aier_suffix}?tid="+tid,page:1}).trigger("reloadGrid");
        
        $("#assign_message_history").dialog("open");
    }
	
</script>
</html>